using UnityEngine;
using System.Collections;
using UnityEditor;

//定制Serializable类的每个实例的GUI
[CustomPropertyDrawer(typeof(cameraShifter))]
public class CameraShifterDrawer : PropertyDrawer 
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        //创建一个属性包装器，用于将常规GUI控件与SerializedProperty一起使用
        using (new EditorGUI.PropertyScope(position, label, property))
        {
            //设置属性名宽度 Name HP
            EditorGUIUtility.labelWidth = 30;
            //输入框高度，默认一行的高度
            position.height = EditorGUIUtility.singleLineHeight;

            //ico 位置矩形
            Rect colliderRec = new Rect(position)
            {
                width = 200,
                height = 20
            };

            Rect sizerec = new Rect(position)
            {
                width = position.width - 210,    //减去icon的width 64
                x = position.x + 210             //在icon的基础上右移64
            };

           

            //找到每个属性的序列化值
            SerializedProperty colliderProperty = property.FindPropertyRelative("collider2D");
            SerializedProperty sizeProperty = property.FindPropertyRelative("size");

            //绘制collider
            colliderProperty.objectReferenceValue = EditorGUI.ObjectField(colliderRec, colliderProperty.objectReferenceValue, typeof(Collider2D), true);

            //绘制size
            sizeProperty.floatValue =
                EditorGUI.FloatField(sizerec, sizeProperty.displayName,
                    sizeProperty
                        .floatValue);

        }
    }
}